package com.ruix.app.mapper;

import com.ruix.app.model.FeedbackAdvice;
import com.ruix.app.model.MessageModel;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/5/7.
 */

public class MessageListMapper implements ApiMapper<ArrayList<MessageModel>>{


    @Override
    public ArrayList<MessageModel> transform(JSONObject response) {
        ArrayList feedbacklList = new ArrayList();
        JSONObject data = response.optJSONObject("data");
        if (data != null) {
            JSONArray messageList = data.optJSONArray("list");
            if (messageList != null && messageList.length() > 0){
                for (int i = 0;i<messageList.length();i++){
                    MessageModel message = new MessageModel().parse(messageList.optJSONObject(i));
                    feedbacklList.add(message);

                }
            }
        }
        return feedbacklList;
    }

}
